package licode.unisop.client.controller;

import licode.unisop.client.utils.SopResult;
import licode.unisop.client.visit.AssetRelVisit;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 定义统一认证平台中心领域相关接口
 *
 * @author licode
 */
@Slf4j
@RestController
@RequestMapping("/uni-api/v1/asset")
public class SopAssetController {
    @Resource
    private AssetRelVisit assetRelVisit;

    /**
     * 保存资源信息
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public SopResult<Object> save(@RequestBody Map<String, Object> asset) {
        assetRelVisit.save(asset);
        return SopResult.of("OK");
    }

    /**
     * 把资源移动到目标资源下（改变其父节点）
     */
    @RequestMapping(value = "/move", method = RequestMethod.POST)
    public SopResult<Object> move(@RequestBody Map<String, Object> req) {
        assetRelVisit.move(req);
        return SopResult.of("OK");
    }

    /**
     * 删除资源
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public SopResult<Object> delete(@RequestBody Map<String, Object> req) {
        assetRelVisit.delete(req);
        return SopResult.of("OK");
    }

    /**
     * 保存资源持有信息（比如保存分组下的权限信息）
     */
    @RequestMapping(value = "/relation/of-holder/save", method = RequestMethod.POST)
    public SopResult<Object> saveAssetsOfHolder(@RequestBody Map<String, Object> req) {
        assetRelVisit.saveAssetsOfHolder(req);
        return SopResult.of("OK");

    }

    /**
     * 移除持有的资源（比如移除分组下的权限信息）
     */
    @RequestMapping(value = "/relation/of-holder/remove", method = RequestMethod.POST)
    public SopResult<Object> removeAssetsOfHolder(@RequestBody Map<String, Object> req) {
        assetRelVisit.removeAssetsOfHolder(req);
        return SopResult.of("OK");
    }

    /**
     * 保存资源持有信息（比如保存持有权限的所有资源信息（比如分组、角色、用户等））
     */
    @RequestMapping(value = "/relation/to-holder/save", method = RequestMethod.POST)
    public SopResult<Object> saveHoldersOfAsset(@RequestBody Map<String, Object> req) {
        assetRelVisit.saveHoldersOfAsset(req);
        return SopResult.of("OK");
    }

    /**
     * 保存资源属性
     */
    @RequestMapping(value = "/attribute/save", method = RequestMethod.POST)
    public SopResult<Object> saveAttributesOfAsset(@RequestBody Map<String, Object> req) {
        assetRelVisit.saveAttributesOfAsset(req);
        return SopResult.of("OK");
    }

    /**
     * 移除资源属性
     */
    @RequestMapping(value = "/attribute/remove", method = RequestMethod.POST)
    public SopResult<Object> removeAttributesOfAsset(@RequestBody Map<String, Object> req) {
        assetRelVisit.removeAttributesOfAsset(req);
        return SopResult.of("OK");
    }
}
